<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>登录-阿西里西后台</title>
    <link rel="shortcut icon" href="./images/favicon.ico">
    <link href="__STATIC__/admin/assets/css/bootstrap.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="__STATIC__/admin/assets/css/font-awesome.min.css"/>
    <!--[if IE 7]>
    <link rel="stylesheet" href="__STATIC__/admin/assets/css/font-awesome-ie7.min.css"/>
    <![endif]-->
    <link rel="stylesheet" href="__STATIC__/admin/assets/css/ace.min.css"/>
    <link rel="stylesheet" href="__STATIC__/admin/assets/css/ace-rtl.min.css"/>
    <link rel="stylesheet" href="__STATIC__/admin/assets/css/ace-skins.min.css"/>
    <link rel="stylesheet" href="__STATIC__/admin/css/style.css"/>
    <!--[if lte IE 8]>
    <link rel="stylesheet" href="__STATIC__/admin/assets/css/ace-ie.min.css"/>
    <![endif]-->
    <script src="__STATIC__/admin/assets/js/ace-extra.min.js"></script>
    <!--[if lt IE 9]>
    <script src="__STATIC__/admin/assets/js/html5shiv.js"></script>
    <script src="__STATIC__/admin/assets/js/respond.min.js"></script>
    <![endif]-->
    <script src="__STATIC__/admin/js/jquery-1.9.1.min.js"></script>
    <script src="__STATIC__/admin/assets/layer/layer.js"></script>
</head>

<body class="login-layout Reg_log_style">
<div class="logintop">
    <span>欢迎后台管理界面平台</span>
    <ul>
        <li><a href="#">返回首页</a></li>
    </ul>
</div>
<div class="loginbody">
    <div class="login-container">
        <div class="center">

        </div>
        <div class="position-relative">
            <span class="version">V<i>1.0.1</i></span>
            <div id="login-box" class="login-box widget-box no-border visible">
                <div class="widget-body">
                    <div class="widget-main">
                        <h4 class="header blue lighter bigger">
                            <i class="icon-coffee green"></i>
                            管理员登录
                        </h4>

                        <div class="login_icon"><img src="__STATIC__/admin/images/login.png"/></div>

                        <form class="">
                            <fieldset>
                                <ul>
                                    <li class="frame_style form_error">
                                        <label class="user_icon"></label>
                                        <input name="username" type="text" id="username"/><i>用户名</i></li>
                                    <li class="frame_style form_error">
                                        <label class="password_icon"></label>
                                        <input name="password" type="password" id="password"/><i>密码</i></li>
                                    <li class="frame_style form_error">
                                        <label class="Codes_icon"></label>
                                        <input name="code" type="text" id="code"/><i>验证码</i>
                                        <div class="Codes_region">
                                            <img src="{:url('login/verify')}" class="verify" alt="">
                                        </div>
                                    </li>

                                </ul>
                                <div class="space"></div>

                                <div class="clearfix">
                                    <label class="inline">
                                        <input type="checkbox" class="ace">
                                        <span class="lbl">保存密码</span>
                                    </label>

                                    <button type="button" class="width-35 pull-right btn btn-sm btn-primary"
                                            id="login_btn">
                                        <i class="icon-key"></i> 登录
                                    </button>
                                </div>

                                <div class="space-4"></div>
                            </fieldset>
                        </form>
                    </div>
                </div>
                <!-- /widget-body -->
            </div>
            <!-- /login-box -->
        </div>
        <!-- /position-relative -->
    </div>
</div>
<div class="loginbm">版权所有 2018 <a href="#">Axlix.com</a></div>

<script>
    //刷新验证码
    $('.verify').on('click', function () {
        var src = "{:url('login/verify')}";
        $(this).attr('src', src);
    })

    //登录
    $('#login_btn').on('click', function () {
        //记录错误次数
        var num = 0;
        //记录错误信息
        var str = "";
        var username = $.trim($('#username').val());
        var password = $.trim($('#password').val());
        var code = $.trim($('#code').val());
        if (username == "") {
            str += '用户名不能为空<br>';
            num++;
        }
        if (password == "") {
            str += '密码不能为空<br>';
            num++;
        }
        if (code == "") {
            str += '验证码不能为空';
            num++;
        }
        //只要num>0，就表明有错误
        if (num > 0) {
            layer.msg(str, {
                title: '错误提示',
                icon: 2
            });
            //return 关键字就是结束函数的执行，后面的代码不再执行
            return false;
        }
        //如果验证都通过，则提交数据进行登录
        var data = {
            username: username,
            password: password,
            code: code
        };
        var url = "{:url('login/login')}";

        $.post(url, data, function (res) {
            if (res.status == 1) {
                location.href='{:url("index/index")}'
            }else{
                layer.msg(res.msg, {
                    title: "错误提示",
                    icon: 2
                });
            }

        }, 'json')

        /* $.ajax({
             type: 'post',
             url: 'login/login',
             data: data,
             dataType:'json',
             success: function (res) {
                 console.log(res);
             }
         });*/

    });
    //按照回车键登录
    $(document).keydown(function (event) {
        if (event.keyCode == 13) {
            $("#login_btn").click();
        }
    });
    $(document).ready(function () {
        $("input[type='text'],input[type='password']").blur(function () {
            var $el = $(this);
            var $parent = $el.parent();
            $parent.attr('class', 'frame_style').removeClass(' form_error');
            if ($el.val() == '') {
                $parent.attr('class', 'frame_style').addClass(' form_error');
            }
        });
        $("input[type='text'],input[type='password']").focus(function () {
            var $el = $(this);
            var $parent = $el.parent();
            $parent.attr('class', 'frame_style').removeClass(' form_errors');
            if ($el.val() == '') {
                $parent.attr('class', 'frame_style').addClass(' form_errors');
            } else {
                $parent.attr('class', 'frame_style').removeClass(' form_errors');
            }
        });
    })
</script>
</body>

</html>
